package com.example.nick.bodyapplication.notification

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.*

class MyReceiver : BroadcastReceiver(), CoroutineScope by MainScope() {

    @OptIn(InternalCoroutinesApi::class)
    override fun onReceive(context: Context, intent: Intent) {
        // This method is called when the BroadcastReceiver is receiving an Intent broadcast.
        val btn_value = intent.extras?.get("Btn_value")
        Log.i("push", "push btn_value:$btn_value")
        launch {
            Log.i("push", "push broad :${Thread.currentThread().name}")
            withContext(Dispatchers.IO) {
                val manger = context.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
                manger.cancel(56)
                Log.i("push", "push broad 000 :${Thread.currentThread().name}")
                delay(5000)
                Log.i("push", "push broad 111 :${Thread.currentThread().name}")
            }
        }
    }
}